<template>
  <div class="orders">
    <my-bread :breadList="breadList"></my-bread>
    <el-card>
      <div class="top">
        <el-input
          placeholder="请输入内容"
          v-model="getOrderFn.query"
          class="input-with-select cc"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="search"
          ></el-button>
        </el-input>
      </div>
      <el-table :data="orderData" border style="width: 100%">
        <el-table-column label="#" type="index" width="100"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="120">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="120">
        </el-table-column>
        <el-table-column prop="order_pay" label="是否付款" width="120">
          <template slot-scope="scope">
            <el-tag :type="scope.row.pay_status | paycolor">{{
              scope.row.pay_status | pay
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="120">
        </el-table-column>
        <el-table-column prop="role_name" label="下单时间" width="300">
          <template slot-scope="scope">
            <p>{{ scope.row.create_time | timer }}</p>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="90">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              circle
              @click="edit(scope.row)"
            ></el-button>
            <el-button
              type="success"
              size="mini"
              icon="el-icon-location"
              circle
              @click="del(scope.row.id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="getOrderFn.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="getOrderFn.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
        >
        </el-pagination>
      </div>
    </el-card>

    <!-- dialog 修改地址-->
    <el-dialog title="修改地址" :visible.sync="dialogAddFormVisible">
      <el-form :model="addressform">
        <el-form-item label="省市区/县" :label-width="formLabelWidth">
          <el-cascader
            :options="options"
            :props="addressProps"
            clearable
          ></el-cascader>
        </el-form-item>

        <el-form-item label="详细地址" :label-width="formLabelWidth">
          <el-input></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogAddFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogAddFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <!-- 物流信息 -->
    <el-dialog title="物流信息" :visible.sync="dialogKuaidiFormVisible">
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities.data"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogKuaidiFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogKuaidiFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getorders, getkuaidi } from "@/http/orders.js";
import _ from "lodash";
getorders;
import { china } from "./china.js";
import { kuaidi } from "./kuaidi.js";
export default {
  data() {
    return {
      total: "",
      getOrderFn: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      orderData: [],
      breadList: [
        {
          path: "/home",
          title: "首页",
        },
        {
          path: "",
          title: "商品管理",
        },
        {
          path: "/params",
          title: "参数列表",
        },
      ],
      dialogAddFormVisible: false,
      addressform: [{}],
      formLabelWidth: "120px",

      options: china,
      addressProps: { checkStrictly: true, value: "code", label: "value" },
      dialogKuaidiFormVisible: false,
      activities: kuaidi,
      reverse:false
    };
  },
  created() {
    this.getorders();
  },
  methods: {
    async getorders() {
      let res = await getorders(this.getOrderFn);
      console.log(res);
      this.orderData = res.data.goods;
      this.total = res.data.total;
    },
    search: _.debounce(function () {
      this.getOrderFn.pagenum = 1;
      this.getorders();
    }, 2000),
    handleSizeChange(val) {
      this.getOrderFn.pagesize = val;
      this.getorders();
    },
    handleCurrentChange(val) {
      this.getOrderFn.pagenum = val;
      this.getorders();
    },
    edit() {
      this.dialogAddFormVisible = true;
    },
    async del() {
      this.dialogKuaidiFormVisible = true;
      let res = await getkuaidi();
    },
  },
};
</script>

<style>
.el-cascader-panel {
  height: 300px;
}
</style>
